#include "gitservercore.h"
#include "settings.h"
#include "gitdaemon.h"
#include <QtCore/QStringList>
#include <QtCore/QTextCodec>
#include <QtGui/QSystemTrayIcon>
#include <QtGui/QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    a.setQuitOnLastWindowClosed(false);

    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));

    // Parse des options à la recherche des options --start ou --stop
    bool start = false;
    bool stop = false;
    foreach(const QString & arg, a.arguments()) {
        if (arg == "--start") {
            start = true;
            break;
        }
        if (arg == "--stop") {
            stop = true;
            break;
        }
    }

    GitServerCore::instance()->connect(&a, SIGNAL(aboutToQuit()), SLOT(deleteLater()));
    GitServerCore::instance()->systemTrayIcon()->show();

    if (start || Settings().mustLaunchGitDaemonOnStartup())
        GitServerCore::instance()->daemon()->start();
    else if (stop)
        GitServerCore::instance()->daemon()->stop();


    return a.exec();
}
